from appium import webdriver
import os
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class Base():
    def __init__(self):
        os.system('adb root')
        cap={
            "platformName": "Android",
            "appium:deviceName": "emulator-5554",
            "appium:noReset": True,
            "appium:appPackage": "com.kongfz.app",
            "appium:appActivity": "com.kongfz.app.home.mvvm.homepage.HomeActivity"
        }
        self.driver=webdriver.Remote('http://127.0.0.1:4723/wd/hub',cap)
        #隐世等待
        self.driver.implicitly_wait(20)
        #查找元素
    def find_ele(self,loc):
        ele=self.driver.find_element(*loc)
        return ele
    #显示等待
    def find_wait_ele(self,loc):
        ele=WebDriverWait(self.driver,10).until(EC.element_to_be_clickable(loc))
        return ele

    #滑动
    def huadong(self,a,b,c,d):
        self.driver.swipe(a,b,c,d,100)

    #截屏
    def jieping(self,a):
        self.driver.save_screenshot(a)

    #轻敲
    def qingqiao(self,a,b):
        self.driver.tap([(a,b)],100)
    #退出
    def tuichu(self):
        self.driver.quit()